<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<script>
description('Check stepping-up and -down for week input fields from renderer.');
if (!window.eventSender)
    debug('This test requires eventSender.');

var input = document.createElement('input');
input.type = 'week';
document.body.appendChild(input);

function setInputAttributes(value, min, max) {
    input.value = value;
    input.min = min;
    input.max = max;
}

function stepUp(value, min, max) {
    setInputAttributes(value, min, max);
    eventSender.keyDown('ArrowUp');
    return input.value;
}

function stepDown(value, min, max) {
    setInputAttributes(value, min, max);
    eventSender.keyDown('ArrowDown');
    return input.value;
}

input.focus();
debug('Function arguments are (value, min, max).');
debug('Week');
shouldBeEqualToString('stepUp("2000-W05", "2000-W05", "2000-W40")', '2000-W06');
shouldBeEqualToString('stepDown("2000-W05", "2000-W05", "2000-W40")', '2000-W40');
shouldBeEqualToString('stepUp("2000-W05", "2000-W02", "2000-W05")', '2000-W02');
shouldBeEqualToString('stepDown("2000-W05", "2000-W02", "2000-W05")', '2000-W04');
shouldBeEqualToString('stepUp("2000-W05", "2000-W08", "2000-W10")', '2000-W08');
shouldBeEqualToString('stepDown("2000-W05", "2000-W08", "2000-W10")', '2000-W10');
shouldBeEqualToString('stepUp("2000-W05", "2000-W03", "2000-W03")', '2000-W03');
shouldBeEqualToString('stepDown("2000-W05", "2000-W03", "2000-W03")', '2000-W03');
shouldBeEqualToString('stepUp("2000-W05", "2000-W03", "2001-W05")', '2000-W06');
shouldBeEqualToString('stepDown("2000-W05", "2000-W05", "2001-W08")', '2000-W04');

debug('Year');
eventSender.keyDown('ArrowRight');
shouldBeEqualToString('stepUp("2000-W01", "2000-W01", "2009-W52")', '2001-W01');
shouldBeEqualToString('stepDown("2000-W01", "2000-W01", "2009-W52")', '2009-W01');
shouldBeEqualToString('stepUp("2000-W01", "1990-W01", "2000-W52")', '1990-W01');
shouldBeEqualToString('stepDown("2000-W01", "1990-W01", "2000-W52")', '1999-W01');
shouldBeEqualToString('stepUp("275760-W01", "1990-W01", null)', '1990-W01');
shouldBeEqualToString('stepDown("1990-W01", "1990-W01", null)', '275760-W01');
shouldBeEqualToString('stepUp("2000-W01", null, "2000-W52")', '0001-W01');
shouldBeEqualToString('stepDown("0001-W01", null, "2000-W52")', '2000-W01');
shouldBeEqualToString('stepUp("1990-W01", "2000-W01", "2009-W52")', '2000-W01');
shouldBeEqualToString('stepDown("1990-W01", "2000-W01", "2009-W52")', '2009-W01');
shouldBeEqualToString('stepUp("2020-W01", "2000-W01", "2000-W52")', '2000-W01');
shouldBeEqualToString('stepDown("2020-W01", "2000-W01", "2000-W52")', '2000-W01');

debug('');
input.remove();
</script>
</body>
</html>
